<template>
	<view class="hotStar">
		<view class="search flex alignCenter">
			<input class="font14" type="text" placeholder="昵称" v-model.trim="name" placeholder-class="font14 color666" maxlength="10" @confirm="searchClick">
			<text class="font14 bold" @click="searchClick">搜索</text>
		</view>
		<!-- <scroll-view class="scrollView" scroll-x="true" :scroll-with-animation="true" enable-flex="true" :scroll-into-view="`sub${scrollId}`" @scroll="scroll">
			<view :class="scrollId==index?'scrollItem font14 bold activeScroll':'scrollItem font14'" :id="`sub${index}`" v-for="(item,index) in subCategory" :key="index" @click.stop="clickScrollItem(item,index)">({{item.subjectCode}}){{item.title}}</view>
		</scroll-view> -->
		<view class="starBox">
			<template v-for="(item,index) in starData">
				<view class="starOne" :key="index" @click="toHomePage(item)">
					<view class="flex alignCenter">
						<image class="avatar" :src="item.avatar || 'https://image.alhelp.net/uploads/20231104/4d491857ac50d21ebbcb25ff5bc254f8.png'" mode="widthFix"></image>
						<view class="starInfo">
							<view class="font14 flex alignCenter justConBetween">
								<view class="bold hiddenOneline">{{item.nickName || '匿名用户'}}</view>
								<view class="focusStyle" v-if="(!item.isLikedUser && item.userId!=userId)" @click.stop="focus(item)"><text class="focusMargin">+</text>关注</view>
							</view>
							<view class="hiddenOneline color999 font12">{{item.introduction}}</view>
							<view class="tags">
								<text class="colorBlue font12" v-for="(item2,idx) in item.schoolTitles" :key="idx">{{item2}}</text>
								<text class="colorBlue font12" v-for="(item2,idx) in item.subjectTitles" :key="idx">{{item2}}</text>
							</view>
						</view>
					</view>
					<view class="flex group">
						<template v-for="(item3,idx) in item.teams">
							<view class="groupOne">
								<uni-mygroup :canAdd="false" :groupItem="item3" :key="idx"></uni-mygroup>
							</view>
						</template>
					</view>
				</view>
			</template>
		</view>
		<uni-nodata v-if="(starData.length==0)" :iconStyle="{'margin':'100rpx 0 0'}"></uni-nodata>
	</view>
</template>

<script>
	import { getSubjectCategory,focusUser } from "@/api/index.js"
	import { quesMoreStar } from "@/api/school.js"
	export default {
		data() {
			return {
				name:'',
				scrollId:'0',
				subCategory:[],
				starData:[],
				chooseSubject:'',
				page:1,
				pageSize:10,
				pageTotal:0,
				userId:''
			};
		},
		onLoad() {
			// this.getCategory()
			this.userId=uni.getStorageSync('userId')
			this.getList();
		},
		methods:{
			initPage(){
				this.page=1;
				this.starData=[];
			},
			searchClick(){
				this.initPage();
				this.getList();
			},
			// 获取分区
			getCategory(){
				let param={"pageNum":1,"pageSize":100,"type":0,"year":new Date().getFullYear()}
				getSubjectCategory(param).then((res)=>{
					if(res.code==100000){
						this.subCategory=res.data.rows
						this.chooseSubject=res.data.rows[0]
						console.log('res',res)
						this.getList()
					}
				})
			},
			// 获取列表
			getList(){
				uni.showLoading({
					title:'加载中',
					mask:true
				})
				let param={
					page:this.page,
					size:this.pageSize,
					nickName:this.name,
				}
				quesMoreStar(param).then((res)=>{
					uni.hideLoading()
					if(res.code==100000){
						this.starData=this.starData.concat(res.data.rows)
						this.pageTotal=Math.ceil(res.data.total/this.pageSize)
					}
				}).catch((err)=>{uni.hideLoading()})
			},
			// 个人首页
			toHomePage(item){
				uni.navigateTo({
					url:'/pages/mine/homePage/homePage?userId='+item.userId
				})
			},
			// 关注
			focus(item){
				let param={
					isAdd:!item.isLikedUser,
					fansUserId:item.userId,
					fansUserName:item.nickName,
					fansUserAvatar:item.avatar,
				}
				focusUser(param).then((res)=>{
					if(res.code==100000){
						item.isLikedUser=!item.isLikedUser
					}
				})
			},
			scroll(e){
				// console.log('scroll',e)
			},
			
			clickScrollItem(item,idx){
				this.chooseSubject=item
				this.scrollId=idx
				this.initPage()
				this.getList()
			}
		},
		onReachBottom() {
			if(this.page<this.pageTotal){
				++this.page
				this.getList()
			}else{
				uni.showToast({
					title:'我也是有底线的',
					icon:'none'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
.search{
	padding: 30rpx 30rpx 0;
	box-sizing: border-box;
	background: #fff;
	input{
		border:1px solid $bordercolor;
		border-radius: 30rpx;
		height: 70rpx;
		line-height: 70rpx;
		padding: 0 20rpx;
		box-sizing: border-box;
		flex:1;
		margin:0 20rpx 0 0;
	}
}
.scrollView{
	white-space: nowrap;
	width: 100%;
	padding: 0 30rpx;
	box-sizing: border-box;
}
.scrollItem{
	display: inline-block;
	height: 80rpx;
	line-height: 80rpx;
	padding: 0 15rpx;
	margin: 0 15rpx;
	text-align: center;
	position:relative;
}
.activeScroll::after{
	content: '';
	display:block;
	position:absolute;
	height: 8rpx;
	width: 100%;
	left:0;
	bottom: 0;
	background:$colorMain;
	border-radius: 20rpx;
	box-shadow: 0 6rpx 10rpx rgba(0, 0, 0, .15);
}
.starList{
	flex-wrap: wrap;
	padding: 30rpx;
	box-sizing: border-box;
	&>view{
		flex: 0 0 48%;
	}
	.starOne{
		margin-bottom: 30rpx;
		border-radius:8rpx;
	}
}
.starBox{
	.starOne{
		border-bottom:20rpx solid $pageBgColor;
		padding: 30rpx;
		box-sizing:border-box;
		.group{
			margin:20rpx 0 0;
			overflow-y: scroll;
		}
		.groupOne{
			flex:0 0 48%;
			margin-right: 20rpx;
			// flex:1;
		}
		.groupOne:last-child{
			margin:0;
		}
	}
	.avatar{
		flex-shrink: 0;
		width: 112rpx;
		height: 112rpx;
		border-radius: 50%;
		margin: 0 30rpx 0 0;
	}
	.starInfo{
		flex:1;
		.tags{
			&>text{
				display: inline-block;
				margin:0 20rpx 0 0;
			}
		}
	}
}
.focusStyle{
	flex-shrink: 0;
}
</style>
